using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.Serialization;
using System.Text;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.Practices.Repository
{
    /// <summary>
    /// This exception is thrown when a invalid parameter
    /// is detected in the repository or database.
    /// </summary>
    [Serializable()]
    [SuppressMessage("Microsoft.Usage", "CA2240:ImplementISerializableCorrectly")]
    public class RepositoryInvalidParameterException : RepositoryException
    {
        private readonly string invalidParameter;

        /// <summary>
        /// Creates a new instance of RepositoryInvalidParameterException.
        /// </summary>
        /// <param name="invalidParameter">The name of the parameter that did not pass the mapping.</param>
        public RepositoryInvalidParameterException(string invalidParameter)
            : this(invalidParameter, null)
        {
        }

        /// <summary>
        /// Creates a new instance of RepositoryValidationException.
        /// </summary>
        /// <param name="invalidParameter">The name of the parameter that did not pass the mapping.</param>
        /// <param name="inner">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
        public RepositoryInvalidParameterException(string invalidParameter, Exception inner)
            : base(string.Format(CultureInfo.CurrentCulture, Microsoft.Practices.Repository.Properties.GenericResources.InvalidParameterName, invalidParameter), inner)
        {
            this.invalidParameter = invalidParameter;
        }

        /// <summary>
        /// Gets the name of the parameter that did not pass the mapping.
        /// </summary>
        public string InvalidParameter
        {
            get { return invalidParameter; }
        }


        /// <summary>
        /// Creates a new instance of RepositoryInvalidParameterException.
        /// </summary>
        public RepositoryInvalidParameterException()
            : base()
        {
        }

        /// <summary>
        /// Creates a new instance of RepositoryInvalidParameterException.
        /// </summary>
        /// <param name="info">The System.Runtime.Serialization.SerializationInfo that holds the serialized data
        /// about the exception being thrown.</param>
        /// <param name="context">The System.Runtime.Serialization.SerializationContext that contains contextual informationa about
        /// the source or destination.</param>
        protected RepositoryInvalidParameterException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }
    }
}
